package onenight.tools.user_interface;

import java.util.ArrayList;
import java.util.List;

import onenight.tools.core.OneNightGameActivity;

public class GameWindowsManager {
	private List<GameWindow> mWindows = new ArrayList<GameWindow>();
	
	private static GameWindowsManager mInstance;
	
	public static GameWindowsManager getInstance()
	{
		if (mInstance==null)
			mInstance = new GameWindowsManager();
		return mInstance;
	}
	
	public List<GameWindow> getOpenedWindows()
	{
		return mWindows;
	}
	
	
	private GameWindowsManager()
	{
		
	}
	
	public void registrateWindow(GameWindow pWindow)
	{
		mWindows.add(pWindow);
	}
	
	public void unregistrateWindow(GameWindow pWindow)
	{
		mWindows.remove(pWindow);
	}
	
	public void closeLast()
	{
		if (mWindows.size()!=0/* && !GameUIPreloader.getInstance().isLoading()*/)
		{
			boolean b = !mWindows.get(mWindows.size()-1).ismOpened();
			mWindows.get(mWindows.size()-1).closeWindow();
			if (b)
				closeLast();
		}
		else
		{
			if (OneNightGameActivity.getInstance().onCloseActivity())
				OneNightGameActivity.getInstance().ImmediatelyCloseActivity();
		}
	}
}
